package stuServlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.StudentDAO;
import dto.StudentDTO;


@SuppressWarnings("serial")
public class doFindByIdServlet extends HttpServlet {

	public doFindByIdServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.process(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.process(request, response);

	}
	
	public void process(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		String id=request.getParameter("id");
		StudentDAO sdao=new StudentDAO();
		StudentDTO dto=sdao.findById(Integer.parseInt(id));
		String birth=dto.getStuBirth();
		String [] str=birth.split("-");
		if(dto!=null){
			request.setAttribute("student", dto);
			request.setAttribute("year", str[0]);
			request.setAttribute("month", str[1]);
			request.setAttribute("day", str[2]);
			request.getRequestDispatcher("stuJsp/findbyid.jsp").forward(request, response);
		}

}

	public void init() throws ServletException {
		// Put your code here
	}

}
